<?php
/**
 * Created by PhpStorm.
 * User: changyifan
 * Date: 2018/1/26
 * Time: 下午3:55
 * 教师模型
 */

namespace Home\Model;
use Think\Model\BaseModel;

class TeacherModel extends BaseModel {

    protected $_link = array(
        'Department' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'Department',
            'foreign_key' => 'dept_id',
            'mapping_fields' => 'sch_id',
            'as_fields' => 'sch_id'
        ),
    );

    protected $_auto = array(
        array('tea_password','md5',3,'function')
    );
    public function getTeacherInfoListByAll(){
        $result = $this->select();
		if($result){
			return $result;
		}else{
			return array();
		}
    }


    public function getTeacherInfoByDepIDAndTeaNum($dep_id,$tea_num){

        if ($dep_id == 0) {
            $con['dept_id'] = array('like', "%%");
        } else {
            $con['dept_id'] = $dep_id;
        }
        $con['tea_id'] = array('like' , "$tea_num%");
        $teacher_info = $this -> where($con)->relation(true) -> select();

        if ($teacher_info) {

            $data = array();
            foreach ($teacher_info as $key => $value) {
                $data[$key]['tea_id'] = $value['tea_id'];
                $data[$key]['tea_name'] = $value['tea_name'];
                $data[$key]['tea_zhi'] = $value['tea_zhi'];
                $data[$key]['tea_manager'] = $value['tea_manager'];
                $data[$key]['tea_sex'] = $value['tea_sex'];
                $data[$key]['dept_id'] = $value['dept_id'];
                $data[$key]['sch_id'] = $value['sch_id'];
                $format = strtotime($value['tea_bir']);
                $data[$key]['tea_bir'] =  date('Y-m-d', $format);
                $data[$key]['tea_status'] = $value['tea_status'];
            }
            return $data;

        } else {
            return array();
        }
    }









    public function check_login($map){
        $isExist = $this -> where($map) -> find();
        if (!$isExist) {
            return "";
        } else {
           session(C('USER_AUTH_KEY'), $isExist['tea_id']);
//           session(C('USER_AUTH_ROLE'), $isExist['permission_grouping_id']);
           return true;
        }
    }

}